package com.woniuxy.hrp.provider;

import com.woniuxy.hrp.entity.Patient;
import org.apache.ibatis.jdbc.SQL;

/**
 * @Description：
 * @Author：曹杰克
 * @CreateTime：2022/8/29 19:28
 * --ffs 增加code 0904
 */
public class PatientMapperSqlProvider {
    public static String updatePatient(Patient patient){
        String sql = new SQL() {
            {
                UPDATE("hrp_patient");
                if (patient.getPassword()!=null && patient.getPassword()!=""){
                    SET("password=#{password}");
                }
                if (patient.getEmail()!=null && patient.getEmail()!=""){
                    SET("email=#{email}");
                }
                if (patient.getPhone()!=null && patient.getPhone()!=""){
                    SET("phone=#{phone}");
                }
                if (patient.getAddress()!=null && patient.getAddress()!=""){
                    SET("address=#{address}");
                }
                if (patient.getIdCard()!=null && patient.getIdCard()!=""){
                    SET("Idcard=#{idCard}");
                }
                if (patient.getId()!=null && patient.getId()!=0){
                    WHERE("id=#{id}");
                }

            }
        }.toString();
        return sql;
    }

    public static String selectPatientByCondition(Patient patient) {
        String sql = new SQL() {
            {
                SELECT("*");
                FROM("hrp_patient");
                if (patient.getAccount() != null) {
                    WHERE("account = #{account}");
                }
                if (patient.getStatus() != null) {
                    WHERE("status = #{status}");
                }
                if (patient.getEmail() != null) {
                    WHERE("email = #{email}");
                }
                if (patient.getPhone() != null) {
                    WHERE("phone = #{phone}");
                }
                if (patient.getAddress() != null) {
                    WHERE("address = #{address}");
                }
                if (patient.getIdCard() != null) {
                    WHERE("Idcard = #{idCard}");
                }
                if (patient.getMlCardNumber() != null) {
                    WHERE("mlcardnumber = #{mlCardNumber}");
                }
            }}.toString();
        return sql;
    }

    public static String getNumsByAccOrEmailOrPhone(Patient patient) {
        String sql = new SQL() {
            {
                SELECT("count(*)");
                FROM("hrp_patient");
                if (patient.getAccount() != null && patient.getAccount()!="") {
                    WHERE("account = #{account}");
                }
                if (patient.getEmail() != null && patient.getEmail()!="") {
                    WHERE("email = #{email}");
                }
                if (patient.getPhone() != null && patient.getPhone()!="") {
                    WHERE("phone = #{phone}");
                }
            }}.toString();
        return sql;
    }
}
